define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'system.Apilist/index',
        add_url: 'system.Apilist/add',
        edit_url: 'system.Apilist/edit',
        delete_url: 'system.Apilist/delete',
        modify_url: 'system.Apilist/modify',
        export_url: 'system.Apilist/export',
        field_list_url: 'system.Apifieldlist/index?type=0',
        refield_list_url: 'system.Apifieldlist/index?type=1',
    };
    var Controller = {

        index: function () {

            ea.table.render({
                init: init,
                cols: [[
                    {type: "checkbox"},
                    {field: 'id', width: 20, title: 'ID'},
                    {field: 'info', minWidth: 40, title: '接口名称'},
                    {
                        field: 'hash', minWidth: 40, title: 'hash', templet: function (d) {

                            return '<a data-open="system.Apilist/apiinfo?hash=' + d.hash + '" data-id=' + d.hash + ' style="color: #108cee;">' + d.hash + '</a>'
                        }
                    },
                    {field: 'apiname', minWidth: 80, title: '真实地址'},
                    {
                        field: 'method', title: '请求方式', width: 120, valueParser(value, data) {
                            if (value == 0) {
                                return "不限";
                            }
                            if (value == 1) {
                                return "Post";
                            }
                            if (value == 2) {
                                return "Get";
                            }
                        }
                    },
                    {
                        field: 'needlogin',
                        title: '登录验证',
                        width: 120,
                        search: 'select',
                        selectList: {0: '否', 1: '是'},
                        templet: ea.table.switch
                    },
                    {
                        field: 'istest', title: '	运行环境', width: 120, valueParser(value, data) {
                            if (value == 0) {
                                return "生产模式";
                            }
                            if (value == 1) {
                                return "测试模式";
                            }
                        }
                    },
                    {
                        field: 'status',
                        title: '状态',
                        width: 85,
                        search: 'select',
                        selectList: {0: '禁用', 1: '启用'},
                        templet: ea.table.switch
                    },
                    {field: 'sort', width: 80, title: '排序', edit: 'text'},
                    {field: 'create_time', minWidth: 80, title: '创建时间', search: 'range'},
                    {
                        width: 250,
                        title: '操作',
                        fixed: 'right',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '请求参数',
                                url: init.field_list_url,
                                method: 'open',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                                extend: "data-full='true'"
                            }],
                            [{
                                text: '返回参数',
                                url: init.refield_list_url,
                                method: 'open',
                                class: 'layui-btn layui-btn-normal layui-btn-xs',
                                extend: "data-full='true'"
                            }],
                            'edit',
                            'delete'
                        ]
                    }
                ]],
            });

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
        apiinfo: function () {
            $(".nav>li").click(function () {
                $(this).addClass("active")
                var id = $(this).attr("data-toggle")
                $(".block-content").hide()
                $("#" + id).show()
            })
            $("#submit").click(function(){	
                var url= $(this).data("url");
                var version = $("#version").val()
                if(!version){
                  layer.msg("请填写版本号");
                  return;
                }		  
                url = url.replace(/versionid/g,version)	
                var formData = $('#form4').serialize();        
                $.post(url,formData,function(result){
                      $("#result").html('返回参数:<pre>' + JSON.stringify(result, null, 4)+ '</pre>')         
                },'json')
           })
        }
    };
    return Controller;
});